<?php
/**
 * Created by viva.
 * User: xj
 * Date: 2015/4/13
 * Time: 14:00
 * 返回给用户的内容
 */
namespace Home\Controller;
class CallbackController extends CommonController
{

    /*
   * 获取到文本类型的数据
   * */
    public function receiveText($postObj)
    {
        $keyword = "你发送的是文本，内容为：" . $postObj->Content;


        $resultStr = $this->callbacktext($keyword, $postObj);
        return $resultStr;

    }

    public function receiveImage()
    {


    }

    public function receiveVideo()
    {
    }

    public function receiveLocation()
    {
    }

    public function receiveVoice()
    {
    }

    public function receiveLink()
    {
    }

    public function receiveEvent()
    {


    }

    /*
     *返回文本的格式化的XML
     * */
    private function callbacktext($keyword, $postObj)
    {
        $textTpl = "<xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<Content><![CDATA[%s]]></Content>
							</xml>";
        if (!empty($keyword)) {
            $msgType = "text";
            $contentStr = $keyword;
            $resultStr = sprintf($textTpl, $postObj->FromUserName, $postObj->toUsername, time(), $msgType, $contentStr);
            return $resultStr;
        }
    }
}